<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>游戏界面</title>
    <script src="js/jquery-1.11.3.js"></script>
    <link href="css/game.css" rel="stylesheet" type="text/css" />
    <script src="js/gobang.js"></script>
    <script src="js/audio.js"></script>
    <link
      href="plugins/jquery-ui-1.13.0.custom/jquery-ui-1.13.0.custom/jquery-ui.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <script
      type="text/javascript"
      src="plugins/jquery-ui-1.13.0.custom/jquery-ui-1.13.0.custom/jquery-ui.js"
    ></script>

    <link
      href="plugins/jquery-ui-1.13.0.custom/jquery-ui-1.13.0.custom/jquery-ui.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <script
      type="text/javascript"
      src="plugins/jquery-ui-1.13.0.custom/jquery-ui-1.13.0.custom/jquery-ui.js"
    ></script>
  </head>
  <body>
    <div class="maindiv">
      <div class="topPage cleanBox">
        <div class="topPageFly">
          <div class="topcurtain"></div>
          <div class="otherInfoBox">
            <div class="Infocontext">
              <div class="Info_name">
                <span id="otherName">？？？？</span>
              </div>
              <div class="Info_avt">
                <img id="otherImg" src="image/问号.png" alt="无" />
              </div>
              <div class="bean_number">
                <i></i>
                <span id="otherBean">？？？？</span>
              </div>
            </div>
            <div class="GoMessage">
              <span id="OtherGoMessage"></span>
            </div>
          </div>
        </div>
      </div>
      <div class="centerContext">
        <div class="talkDiv">
          <div id="textMes" class="textMes"></div>
          <div class="talk_Text">
            <input id="talkText" type="text" placeholder="请输入聊天内容" />
            <a onclick="sendTextMes()">发送</a>
          </div>
          <div class="talk_Spead cleanBox">
            <div
              onmousedown="speakAnimateBegin()"
              onmouseup="speakAnimateEnd()"
              class="talk_Spead_Butten cleanBox"
            >
              <i></i>
              <span
                >按住说话
                <div class="talk_Spead_Butten_span_div"></div>
                <div class="talk_Spead_Butten_span_div2"></div>
                <div class="talk_Spead_Butten_span_div3"></div
              ></span>
            </div>
          </div>
        </div>
        <div class="BangDiv">
          <div id="myBang"></div>
        </div>
        <div class="Tips">
          <div class="system_Tip">
            <span id="SystemTip">我方先手</span>
          </div>
          <ul class="Tips_Choose">
            <li>
              <a onclick="reopenMessage()">重开</a><i id="myReopen"></i
              ><i id="otherReopen"></i>
            </li>
            <li>
              <a onclick="regretMessage()">悔棋</a><i id="myRegret"></i
              ><i id="otherRegret"></i>
            </li>
            <li><a onclick="AdmitDefeatMessage()">认输</a><i></i><i></i></li>
          </ul>
        </div>
      </div>
      <div class="bottomPage">
        <div class="bottomPageFly">
          <div class="myInfoBox">
            <div class="Infocontext">
              <div class="Info_name">
                <span id="MyName">？？？？</span>
              </div>
              <div class="Info_avt">
                <img id="MyImg" src="image/问号.png" alt="无" />
              </div>
              <div class="bean_number">
                <i></i>
                <span id="MyBean">？？？？</span>
              </div>
            </div>
            <div class="GoMessage">
              <span id="MyGoMessage"></span>
            </div>
          </div>
          <div class="bottomcurtain"></div>
        </div>
      </div>
    </div>
    <div id="RegretDialog" style="display: none">
      <div class="RegretDialog_div cleanBox">
        <span>是否同意对方悔棋请求？</span>
        <div class="RegretDialog_div_butten">
          <a onclick="regretConfirm(0)" class="dialog_butten dialog_yes"
            >同意</a
          >
          <a onclick="regretConfirm(1)" class="dialog_butten dialog_no"
            >不同意</a
          >
        </div>
      </div>
    </div>
    <div id="ReopenDialog" style="display: none">
      <div class="RegretDialog_div cleanBox">
        <span>是否同意对方重开请求？</span>
        <div class="RegretDialog_div_butten">
          <a onclick="reopenConfirm(0)" class="dialog_butten dialog_yes"
            >同意</a
          >
          <a onclick="reopenConfirm(1)" class="dialog_butten dialog_no"
            >不同意</a
          >
        </div>
      </div>
    </div>
    <audio id="myauido" src=""></audio>
  </body>
  <script>
    //页面了参数
    var pageParams = new Object();
    var gameBegin = false;
    var isMe = false;
    var goColor = 1;
    var isWait = false;
    var isClick = true;

    //页面加载时触发
    $(function () {
      //初始化
      initWs();
      //获取页面参数
      initPage();

      initGoBang();

      InitAudio({
        enableUpload: true, //支持音频文件上传
        url: "http://localhost:8080/audio/upload",
        uploadSucc: function (data) {
          console.log("音频文件上传成功，文件名：" + data);

          //将该语音消息发送给对方
          var msg = new Object();
          msg.msgType = 210;
          msg.audio = data;
          sendMsgToServer(msg);

          //本地生成一条录音消息，再通过websocket发送给对方
          showInfo2Div(
            "我",
            "<a onclick='playAudio(\"" + data + "\")'>语音消息</a>"
          );
        },
      });
    });

    function initGoBang() {
      new GoBang({
        id: "myBang",
        click: function (x, y) {
          if (gameBegin && isMe && !isWait && isClick) {
            //准备一个信息，将落子信息传递给WebSocket服务器
            var msg = new Object();
            msg.msgType = 202; //落子信息
            msg.x = x;
            msg.y = y;
            msg.goColor = goColor; //落子的颜色
            //消息通知服务器
            sendMsgToServer(msg); //将落子信息 告诉服务器
          }
        },
      });
    }

    //初始化WebSocket
    var ws;
    function initWs() {
      //判断浏览器是否支持WebSocket技术
      if (window.WebSocket) {
        //支持websocket

        //连接websocket服务器
        ws = new WebSocket("ws://localhost:8080/gobank");

        //给ws对象设置回调方法
        ws.onopen = function () {
          showInfo2Div("系统", "已经成功连接了服务器");
          //初始化房间
          initRoom();
        };

        ws.onclose = function () {
          showInfo2Div("系统", "与服务器的连接已经断开");
        };

        ws.onerror = function (e) {
          showInfo2Div("系统", "与服务器连接发生异常");
        };

        ws.onmessage = function (resp) {
          var msg = JSON.parse(resp.data);
          console.log(msg);
          if (msg.code == 300) {
            showInfo2Div("系统", msg.mes);
          } else if (msg.code == 303) {
            showInfo2Div("系统", msg.mes);
          } else if (msg.code == 400) {
            var header = msg.ext.user.header;
            var nickname = msg.ext.user.nickname;
            var uid = msg.ext.user.id;
            var beanNumber = msg.ext.user.happyBean;

            $("#otherImg").attr(
              "src",
              "http://localhost:8080/img/getImg?imageName=" + header
            );
            $("#otherName").text(nickname);
            $("#otherBean").html(happybeanNumberConverse(beanNumber + ""));

            isMe = true; //房主默认先手

            goColor = 0; //房主默认执黑

            beginGameAnimate("我方先手");

            showInfo2Div("系统", nickname + "加入房间");
          } else if (msg.code == 401) {
            var header = msg.ext.user.header;
            var nickname = msg.ext.user.nickname;
            var uid = msg.ext.user.id;
            var beanNumber = msg.ext.user.happyBean;

            $("#otherImg").attr(
              "src",
              "http://localhost:8080/img/getImg?imageName=" + header
            );
            $("#otherName").text(nickname);
            $("#otherBean").html(happybeanNumberConverse(beanNumber + ""));

            isMe = false; //房主默认先手

            goColor = 1; //房主默认执黑

            beginGameAnimate("等待对方先手");

            showInfo2Div("系统", "成功加入" + nickname + "房间");
          } else if (msg.code == 402) {
            //对手的落子信息
            var x = msg.ext.goBand.x;
            var y = msg.ext.goBand.y;
            var otherColor = msg.ext.goBand.color;
            var isWin = msg.ext.isWin; //对方是否胜利
            //将对手的落子信息绘制到我的棋盘上
            drawGo(x, y, otherColor);
            $("#SystemTip").hide();
            if (isWin) {
              //对方胜利
              gameBegin = false;
              ShowSys_CloseGoMes("redFont", "我方失败");
              var beanNumber = localStorage.getItem("happyBean");
              localStorage.setItem("happyBean", parseInt(beanNumber) - 1000);
              return;
            } else {
              isMe = true;
              //我方落子
              ShowMe_CloseOther("我方落子中");
            }
          } else if (msg.code == 403) {
            //自己落子成功
            var x = msg.ext.goBand.x;
            var y = msg.ext.goBand.y;
            var meColor = msg.ext.goBand.color;
            var isWin = msg.ext.isWin; //我方是否胜利
            //在自己的棋盘上 绘制自己的落子信息
            drawGo(x, y, meColor);
            $("#SystemTip").hide();
            if (isWin) {
              //对方胜利
              gameBegin = false;
              ShowSys_CloseGoMes("greenFont", "我方胜利");
              var beanNumber = localStorage.getItem("happyBean");
              localStorage.setItem("happyBean", parseInt(beanNumber) + 1000);

              return;
            } else {
              //转让落子的权利
              isMe = false;
              ShowOther_CloseMe("对方落子中");
            }
          } else if (msg.code == 404) {
            showInfo2Div("对方", msg.ext.mes);
            $("#textMes")[0].scrollTop = $("#textMes")[0].scrollHeight;
          } else if (msg.code == 405) {
            //重开请求
            if (msg.ext.code == 0) {
              $("#myReopen").addClass("Wait_Confirm");
              $("#otherReopen").addClass("Wait_Wait");
              isWait = true;
            } else {
              $("#myReopen").addClass("Wait_Wait");
              $("#otherReopen").addClass("Wait_Confirm");
              $("#ReopenDialog").dialog({
                title: "悔棋请求",
                width: 400,
                height: 200,
              });
              isWait = true;
            }
          } else if (msg.code == 407) {
            //重开确认
            $("#myReopen").removeClass();
            $("#otherReopen").removeClass();
            $("#myReopen").addClass("Wait_Confirm");
            $("#otherReopen").addClass("Wait_Confirm");
            setTimeout(function () {
              reopen();
              $("#myReopen").removeClass();
              $("#otherReopen").removeClass();
              isWait = false;
            }, 2000);
          } else if (msg.code == 408) {
            //重开拒绝
            if (msg.ext.code == 0) {
              $("#myReopen").removeClass();
              $("#myReopen").addClass("Wait_Oppose");
            } else {
              $("#otherReopen").removeClass();
              $("#otherReopen").addClass("Wait_Oppose");
            }
            setTimeout(function () {
              $("#myReopen").removeClass();
              $("#otherReopen").removeClass();
              isWait = false;
            }, 2000);
          } else if (msg.code == 409) {
            //悔棋请求
            if (msg.ext.code == 0) {
              $("#myRegret").addClass("Wait_Confirm");
              $("#otherRegret").addClass("Wait_Wait");
            } else {
              $("#myRegret").addClass("Wait_Wait");
              $("#otherRegret").addClass("Wait_Confirm");
              $("#RegretDialog").dialog({
                title: "悔棋请求",
                width: 400,
                height: 200,
              });
            }
            isWait = true;
          } else if (msg.code == 410) {
            //悔棋确认
            $("#myRegret").removeClass();
            $("#otherRegret").removeClass();
            $("#myRegret").addClass("Wait_Confirm");
            $("#otherRegret").addClass("Wait_Confirm");
            setTimeout(function () {
              regret(msg);
              $("#myRegret").removeClass();
              $("#otherRegret").removeClass();
              isWait = false;
            }, 2000);
          } else if (msg.code == 411) {
            //悔棋拒绝
            if (msg.ext.code == 0) {
              $("#myRegret").removeClass();
              $("#myRegret").addClass("Wait_Oppose");
            } else {
              $("#otherRegret").removeClass();
              $("#otherRegret").addClass("Wait_Oppose");
            }
            setTimeout(function () {
              $("#myRegret").removeClass();
              $("#otherRegret").removeClass();
              isWait = false;
            }, 2000);
          } else if (msg.code == 412) {
            //对方认输
            isWin = true;
            gameBegin = false;
            if (msg.ext.code == 0) {
              ShowSys_CloseGoMes("greenFont", "对方认输，我方胜利");
            } else {
              //对方胜利
              ShowSys_CloseGoMes("redFont", "我方失败");
            }
            var beanNumber = localStorage.getItem("happyBean");
            localStorage.setItem("happyBean", parseInt(beanNumber) - 1000);
          } else if (msg.code == 413) {
            //有人加入观战
            if (msg.ext.code == 0) {
              if (msg.ext.isReady == 0) {
                var header = msg.ext.player1.header;
                var nickname = msg.ext.player1.nickname;
                var beanNumber = msg.ext.player1.happyBean;
                ShowMe_CloseOther("等待对手中");
                $("#MyImg").attr(
                  "src",
                  "http://localhost:8080/img/getImg?imageName=" + header
                );
                $("#MyName").text(nickname);
                $("#MyBean").html(happybeanNumberConverse(beanNumber + ""));
              } else {
                var header = msg.ext.player1.header;
                var nickname = msg.ext.player1.nickname;
                var beanNumber = msg.ext.player1.happyBean;

                $("#MyImg").attr(
                  "src",
                  "http://localhost:8080/img/getImg?imageName=" + header
                );
                $("#MyName").text(nickname);
                $("#MyBean").html(happybeanNumberConverse(beanNumber + ""));
                header = msg.ext.player2.header;
                nickname = msg.ext.player2.nickname;
                beanNumber = msg.ext.player2.happyBean;
                $("#otherImg").attr(
                  "src",
                  "http://localhost:8080/img/getImg?imageName=" + header
                );
                $("#otherName").text(nickname);
                $("#otherBean").html(happybeanNumberConverse(beanNumber + ""));
                showInfo2Div("系统", "成功加入观战");

                isClick = false;

                $("#SystemTip").hide();

                ReGoBang(msg.ext.step);
                beginGameAnimate("等待开始");
              }
            } else {
              showInfo2Div("系统", msg.ext.user.nickname + "&nbsp;加入观战");
            }
          } else if (msg.code == 414) {
            //玩家落子
            $("#SystemTip").hide();
            drawGo(msg.ext.goBand.x, msg.ext.goBand.y, msg.ext.goBand.color);
            if (msg.ext.user == 0) {
              ShowOther_CloseMe("落子中");
              showOtherTip(Tip);
            } else {
              ShowMe_CloseOther("落子中");
            }
            if (msg.ext.isWin) {
              gameBegin = false;
              ShowSys_CloseGoMes(
                "greenFont",
                msg.ext.goBand.color == 0 ? "黑方胜利" : "白方胜利"
              );
            }
          } else if (msg.code == 415) {
            //玩家发送消息
            showInfo2Div(msg.ext.userName, msg.ext.mes);
          } else if (msg.code == 416) {
            //玩家重开
            ShowSys_CloseGoMes("blackFont", "双方重开中");
            setTimeout(function () {
              reGameAnimate("等待开始");
            }, 2000);
          } else if (msg.code == 417) {
            //玩家悔棋
            ShowSys_CloseGoMes("blackFont", "双方悔棋中");
            setTimeout(function () {
              ReGoBang(msg.ext.step);
              ShowSys_CloseGoMes("blackFont", "等待开始");
            }, 2000);
          } else if (msg.code == 418) {
            //玩家认输
            gameBegin = false;
            ShowSys_CloseGoMes(
              "greenFont",
              msg.ext.user == 1 ? "白方认输，黑方胜利" : "黑方认输，白方胜利"
            );
          } else if (msg.code == 419) {
            //音频消息
            var audio = msg.ext.audio;
            //展示到聊天框中
            showInfo2Div(
              "对方",
              "<a onclick='playAudio(\"" + audio + "\")'>语音消息</a>"
            );
          } else if (msg.code == 420) {
            //
            var audio = msg.ext.audio;
            var name = msg.ext.user.nickname;
            //展示到聊天框中
            showInfo2Div(
              name,
              "<a onclick='playAudio(\"" + audio + "\")'>语音消息</a>"
            );
          } else if (msg.code == 421) {
            var header = msg.ext.user.header;
            var nickname = msg.ext.user.nickname;
            var uid = msg.ext.user.id;
            var beanNumber = msg.ext.user.happyBean;

            $("#otherImg").attr(
              "src",
              "http://localhost:8080/img/getImg?imageName=" + header
            );
            $("#otherName").text(nickname);
            $("#otherBean").html(happybeanNumberConverse(beanNumber + ""));
            beginGameAnimate("等待开始");
            showInfo2Div("系统", "成功加入观战");
            isClick = false;
          }
        };
      } else {
        alert("您的浏览器不支持此游戏");
      }
    }

    //发送消息到服务器
    function sendMsgToServer(msg) {
      if (ws) {
        if (typeof msg != "string") {
          //非字符串消息
          msg = JSON.stringify(msg);
        }
        //只发送字符串
        ws.send(msg);
      }
    }

    //初始化页面
    function initPage() {
      //获得上一个页面传递的参数
      var url = location.href;
      var i = url.indexOf("?"); //获取？的位置
      if (i != -1) {
        //截取字符串
        var params = url.substring(i + 1);

        //获取参数的分隔符
        var arrays = params.split("&");
        for (var j = 0; j < arrays.length; j++) {
          //用=符号截取参数的 key - value
          var key = arrays[j].split("=")[0];
          var value = arrays[j].split("=")[1];
          //将解析的key和value 放入 页面的全局变量
          pageParams[key] = value;
        }
      } else {
        alert("请从主页加入房间");
      }
    }

    //初始化房间
    function initRoom() {
      console.log(pageParams);
      if (pageParams.action == 1) {
        console.log("创建房间...");

        //走创建房间的逻辑
        createRoom();
      } else if (pageParams.action == 0) {
        console.log("加入房间...");

        //走加入房间的逻辑
        addRoom();
      } else if (pageParams.action == 2) {
        console.log("加入观战...");
        joinRoom();
      }
    }

    //创建房间的逻辑
    function createRoom() {
      //发送websocket信息

      //准备的一个消息的协议
      var msg = new Object();
      msg.msgType = 200; //告诉服务器 - 创建房间的消息
      msg.info = decodeURI(pageParams.info); //告诉服务器 - 房间的信息
      msg.pass = pageParams.pass; //房间的密码
      msg.isSub = pageParams.isSub;

      //用户信息 - 谁创建的房间
      msg.uid = localStorage.getItem("uid");
      msg.nickname = localStorage.getItem("nickname");
      msg.header = localStorage.getItem("header");
      msg.beanNumber = localStorage.getItem("happyBean");

      $("#MyImg").attr(
        "src",
        "http://localhost:8080/img/getImg?imageName=" + msg.header
      );
      $("#MyName").text(msg.nickname);
      $("#MyBean").html(happybeanNumberConverse(msg.beanNumber));
      //消息通知服务器
      sendMsgToServer(msg);
      ShowMe_CloseOther("等待对手中");
    }

    //加入房间的逻辑
    function addRoom() {
      //发送websocket信息

      //准备一个消息的协议对象
      var msg = new Object();
      msg.msgType = 201; //加入房间
      msg.rid = pageParams.rid; //房间号
      msg.roomCode = pageParams.roomCode; //房间验证码

      //用户信息 - 谁加入的房间
      msg.uid = localStorage.getItem("uid");
      msg.nickname = localStorage.getItem("nickname");
      msg.header = localStorage.getItem("header");
      msg.beanNumber = localStorage.getItem("happyBean");

      $("#MyImg").attr(
        "src",
        "http://localhost:8080/img/getImg?imageName=" + msg.header
      );
      $("#MyName").text(msg.nickname);
      $("#MyBean").html(happybeanNumberConverse(msg.beanNumber));
      //消息通知服务器
      sendMsgToServer(msg);
    }

    function joinRoom() {
      //准备一个消息的协议对象
      var msg = new Object();
      msg.msgType = 209; //加入房间
      msg.rid = pageParams.rid; //房间号
      //消息通知服务器
      msg.uid = localStorage.getItem("uid");
      msg.nickname = localStorage.getItem("nickname");
      sendMsgToServer(msg);
    }

    /**
     * 展示聊天内容到聊天框
     * **/
    function showInfo2Div(user, msg) {
      var html =
        '<ul><span title="' +
        user +
        '">[' +
        user +
        "]:</span><i>" +
        msg +
        "</i></ul>";
      $("#textMes").append(html);
      $("#textMes")[0].scrollTop = $("#textMes")[0].scrollHeight;
    }

    /**
     * 我方落子消息动画
     * **/
    var timeOut = null;
    var Tip;
    var count = 0;
    function showMyTip(tip) {
      if (count != 4) {
        timeOut = setTimeout(function () {
          $("#MyGoMessage").text(tip + ".");
          tip = tip + ".";
          count++;
          showMyTip(tip);
        }, 1000);
      } else {
        count = 0;
        tip = Tip;
        $("#MyGoMessage").text(tip);
        showMyTip(tip);
      }
    }

    /**
     * 对方落子信息动画
     * **/
    function showOtherTip(tip) {
      if (count != 4) {
        timeOut = setTimeout(function () {
          $("#OtherGoMessage").text(tip + ".");
          tip = tip + ".";
          count++;
          showOtherTip(tip);
        }, 1000);
      } else {
        count = 0;
        tip = Tip;
        $("#OtherGoMessage").text(tip);
        showOtherTip(tip);
      }
    }

    /**
     *
     * 欢乐豆转换
     * **/
    function happybeanNumberConverse(happyNumber) {
      var reust;
      var Billion;
      var Thousand;
      var Hundred;
      var len;
      var regex = /^\d{9,}$/;
      if (happyNumber.match(regex) == null) {
        regex = /^\d{5,}$/;
        if (happyNumber.match(regex) == null) {
          return happyNumber;
        } else {
          Thousand = parseInt(happyNumber / 10000);
          len = Thousand.toString().length;
          console.log(len);
          if (len == 1) {
            Hundred = parseInt(happyNumber / 10);
            reust = Hundred / 1000;
          }
          if (len == 2) {
            Hundred = parseInt(happyNumber / 100);
            reust = Hundred / 100;
          }
          if (len == 3) {
            Hundred = parseInt(happyNumber / 1000);
            reust = Hundred / 10;
          }
          if (len == 4) {
            Hundred = parseInt(happyNumber / 10000);
            reust = Hundred;
          }
          return reust + "&nbsp;万";
        }
      } else {
        Billion = parseInt(happyNumber / 100000000);
        len = Billion.toString().length;
        if (len == 1) {
          Thousand = parseInt(happyNumber / 100000);
          reust = Thousand / 1000;
        }
        if (len == 2) {
          Thousand = parseInt(happyNumber / 1000000);
          reust = Thousand / 100;
        }
        if (len == 3) {
          Thousand = parseInt(happyNumber / 10000000);
          reust = Thousand / 10;
        }
        if (len == 4) {
          Thousand = parseInt(happyNumber / 100000000);
          reust = Thousand;
        }
        return reust + "&nbsp;亿";
      }
    }

    /**
     * 开始动画
     *
     * **/
    function beginGameAnimate(mes) {
      ShowSys_CloseGoMes("blackFont", mes);
      $(".topcurtain").animate({ height: "0px" }, 1000);
      $(".bottomPageFly").animate({ top: "0px" }, 1000);
      $(".bottomcurtain").animate({ height: "0px" }, 1000, function () {
        gameBegin = true; //游戏开始
      });
    }

    /**
     *
     * 结束动画
     * **/
    function endGameAnimate() {
      $(".topcurtain").animate({ height: "250px" }, 1000);
      $(".bottomPageFly").animate({ top: "-250px" }, 1000);
      $(".bottomcurtain").animate({ height: "250px" }, 1000, function () {
        $("#SystemTip").text("");
        $("#SystemTip").removeClass();
        ReGoBang("");
        if (goColor == 1) {
          isMe = false; //房主默认先手
          setTimeout(function () {
            beginGameAnimate("对方先手");
          }, 1000);
        } else {
          isMe = true; //房主默认先手
          setTimeout(function () {
            beginGameAnimate("我方先手");
          }, 1000);
        }
      });
    }

    /**
     * 重开动画
     * **/
    function reGameAnimate(mes) {
      $("#OtherGoMessage").hide();
      $("#MyGoMessage").hide();
      $(".topcurtain").animate({ height: "250px" }, 1000);
      $(".bottomPageFly").animate({ top: "-250px" }, 1000);
      $(".bottomcurtain").animate({ height: "250px" }, 1000, function () {
        ShowSys_CloseGoMes("blackFont", mes);
        ReGoBang("");
        setTimeout(function () {
          beginGameAnimate(mes);
        }, 1000);
      });
    }

    /**
     * 发送聊天消息
     */
    function sendTextMes() {
      if (!isClick) {
        return;
      }
      var talkText = $("#talkText").val();
      if (talkText == null || talkText.trim() == "") {
        alert("请输入聊天内容");
        return;
      }
      var msg = new Object();
      msg.msgType = 203; //告诉服务器 - 聊天信息
      msg.mes = talkText; //告诉服务器 - 聊天信息
      sendMsgToServer(msg);
      showInfo2Div("我", talkText);
      $("#talkText").val("");
    }

    /**
     * 开始录音
     * **/
    function speakAnimateBegin() {
      if (!isClick) {
        return;
      }
      $(".talk_Spead_Butten_span_div").addClass("pointToRoute");
      $(".talk_Spead_Butten_span_div2").addClass("pointToRoute2");
      $(".talk_Spead_Butten_span_div3").addClass("pointToRoute3");
      startRecoder();
    }
    /**
     * 结束录音
     * **/
    function speakAnimateEnd() {
      if (!isClick) {
        return;
      }
      $(".talk_Spead_Butten_span_div").removeClass("pointToRoute");
      $(".talk_Spead_Butten_span_div2").removeClass("pointToRoute2");
      $(".talk_Spead_Butten_span_div3").removeClass("pointToRoute3");
      stopRecoder();
    }

    /**
     * 重开消息
     * **/
    function reopenMessage() {
      if (!isClick) {
        return;
      }
      if (isWait) {
        alert("请等待上一个请求结束");
      } else {
        var msg = new Object();
        msg.msgType = 204; //告诉服务器 - 重开的消息
        sendMsgToServer(msg);
      }
    }

    /**
     * 悔棋消息
     * **/
    function regretMessage() {
      if (!isClick) {
        return;
      }
      if (gameBegin == false) {
        return;
      }
      if (isWait) {
        alert("请等待上一个请求结束");
      } else {
        var msg = new Object();
        msg.msgType = 206; //告诉服务器 - 悔棋的消息
        sendMsgToServer(msg);
      }
    }

    /**
     * 认输
     * **/
    function AdmitDefeatMessage() {
      if (!isClick) {
        return;
      }
      if (gameBegin == false) {
        return;
      }
      if (isWait) {
        alert("请等待上一个请求结束");
      } else {
        var msg = new Object();
        msg.msgType = 208; //告诉服务器 - 悔棋的消息
        sendMsgToServer(msg);
      }
    }
    /**
     * 悔棋确认
     * **/
    function regretConfirm(num) {
      if (!isClick) {
        return;
      }
      var msg = new Object();
      msg.msgType = 207;
      if (isMe) {
        msg.isMe = 0;
      } else {
        msg.isMe = 1;
      }
      msg.isConfirm = num + "";
      sendMsgToServer(msg);
      $("#RegretDialog").dialog("close");
    }

    /**
     * 重开确认
     * **/
    function reopenConfirm(num) {
      if (!isClick) {
        return;
      }
      var msg = new Object();
      msg.msgType = 205;
      msg.isConfirm = num + "";
      sendMsgToServer(msg);
      $("#ReopenDialog").dialog("close");
    }

    /**
     * 重开动作
     */
    function reopen() {
      if (goColor == 1) {
        isMe = false; //房主默认先手
        reGameAnimate("对方先手");
      } else {
        isMe = true; //房主默认先手
        reGameAnimate("我方先手");
      }
    }

    /**
     * 悔棋动作
     */
    function regret(mes) {
      $("#SystemTip").hide();
      if (mes.ext.isMe == 0) {
        ShowOther_CloseMe("对方落子中");
        isMe = false;
      } else {
        ShowMe_CloseOther("我方落子中");
        isMe = true;
      }
      ReGoBang(mes.ext.step);
    }

    /**
     * 重置棋盘
     */
    function ReGoBang(List) {
      $("#myBang").empty();
      initGoBang();
      if (List != "") {
        for (var i = 0; i < List.length; i++) {
          drawGo(List[i][0], List[i][1], List[i][2]);
        }
      }
    }

    /**
     * 清除落子消息并且显示系统消息
     */
    function ShowSys_CloseGoMes(color, mes) {
      clearTimeout(timeOut);
      $("#OtherGoMessage").hide();
      $("#MyGoMessage").hide();
      $("#SystemTip").removeClass();
      $("#SystemTip").addClass(color);
      $("#SystemTip").text(mes);
      $("#SystemTip").show();
    }
    /**
     * 对方落子消息
     * **/
    function ShowOther_CloseMe(mes) {
      clearTimeout(timeOut);
      Tip = mes;
      $("#MyGoMessage").hide();
      $("#OtherGoMessage").text(mes);
      $("#OtherGoMessage").show();
      showOtherTip(mes);
    }
    /**
     * 对方落子消息
     * **/
    function ShowMe_CloseOther(mes) {
      clearTimeout(timeOut);
      Tip = mes;
      $("#OtherGoMessage").hide();
      $("#MyGoMessage").text(mes);
      $("#MyGoMessage").show();
      showMyTip(mes);
    }

    /**
     * 播放音频
     */
    function playAudio(filename) {
      //通过一个音频标签播放
      $("#myauido").attr(
        "src",
        "http://localhost:8080/audio/get?filename=" + filename
      );
      //播放音频
      $("#myauido")[0].play();
    }
  </script>
</html>
